import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToMany,
  JoinTable,
} from 'typeorm';
import { SysUser } from '../../sys-user/entities/sys-user.entity';

@Entity('sys_post')
export class SysPost {
  @PrimaryGeneratedColumn({ comment: '岗位ID' })
  post_id: number;

  @Column({ comment: '岗位编码', nullable: true })
  post_code: string;

  @Column({ comment: '岗位名称', nullable: true })
  post_name: string;

  @Column({ comment: '显示顺序', nullable: true })
  post_sort: number;

  @Column({ comment: '状态（0正常 1停用）', nullable: true })
  status: string;

  @Column({ default: '', comment: '创建者' })
  create_by: string;

  @Column({ comment: '创建时间', type: 'datetime' })
  create_time: Date;

  @Column({ default: '', comment: '更新者' })
  update_by: string;

  @Column({ comment: '更新时间', type: 'datetime' })
  update_time: Date;

  @Column({ comment: '备注' })
  remark: string;

  @ManyToMany(() => SysUser, (user) => user.posts)
  @JoinTable({
    name: 'sys_user_post',
    joinColumn: { name: 'post_id', referencedColumnName: 'post_id' },
    inverseJoinColumn: { name: 'user_id', referencedColumnName: 'user_id' },
  })
  users: SysUser[];
}
